define(function (require, exports, module) {
    var tpl = require('./index.html');
    const apis = require('./apis');
    var MD5Util = require('/utils/md5.js')
    var app={
        template: tpl,
        data() {
            return {
                dialogFormVisible:false,
                form:{
                    mode:1, // 输入模式 1-ak 2-密码 3-验证码
                    env:'v5', // 所属环境
                    loginName:'', // 用户名
                    password:'', // 密码
                    ak:'',
                },
                envList:[
                    {value:'dev',label:'开发环境'},
                    {value:'test',label:'测试环境'},
                    {value:'beta',label:'预发布环境'},
                    {value:'v5',label:'正式环境'},
                ]
            }
        },
        methods: {
            addHandle() {
                this.dialogFormVisible = true;
            },
            clearHandle() {

            },
            deleteHandle() {

            },
            // 重新登录
            refresh() {

            },
            conformHandle() {
                const mode = this.form.mode;
                if(mode===1) {
                    this.form.loginName = '';
                    this.form.password = '';
                    apis.getUserInfoByAk(this.form,this.form.env).then(res=>{
                        if(res){
                            this.dialogFormVisible = false;
                        } else {

                        }
                    })
                } else if(mode===2) {
                    this.form.ak = '';
                    const data = Object.assign({},this.form);
                    data.password = MD5Util.hexMd5(data.password);
                    apis.login4password(data,this.form.env).then(res=>{
                        console.log(res);
                    })
                }

            },
            cancelHandle() {
                this.dialogFormVisible = false;
            }
        }
    }
    module.exports = app
})


